package com.mrx.commons.logback.provider;

import ch.qos.logback.classic.spi.ILoggingEvent;
import com.fasterxml.jackson.core.JsonGenerator;
import net.logstash.logback.composite.AbstractFieldJsonProvider;
import net.logstash.logback.composite.FieldNamesAware;
import net.logstash.logback.composite.JsonWritingUtils;
import net.logstash.logback.fieldnames.LogstashFieldNames;

import java.io.IOException;

/**
 * openObserve 日志收集器自定义参数
 *
 * @author Mr.X
 * @since 2023-12-09 下午 11:16:32
 */
public class OpenObserveJsonProvider extends AbstractFieldJsonProvider<ILoggingEvent> implements FieldNamesAware<LogstashFieldNames> {

    @Override
    public void setFieldNames(LogstashFieldNames fieldNames) {

    }

    @Override
    public void writeTo(JsonGenerator generator, ILoggingEvent event) throws IOException {
        JsonWritingUtils.writeStringField(generator, "_timestamp", String.valueOf(event.getTimeStamp()));
    }
}
